package com.example.demo.dto;

import com.example.demo.entity.Bookkeeping;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
public class BookkeepingResponseDto {
    private Integer id;
    private Integer type; // 0: 收入 1: 支出
    private LocalDate bookDate;
    private String category;
    private BigDecimal price;
    private String remark;
    private LocalDateTime addTime;
    private LocalDateTime updateTime;
    private Integer year;
    private Integer month;

    public static BookkeepingResponseDto fromBookkeeping(Bookkeeping bookkeeping) {
        if (bookkeeping == null) {
            return null;
        }
        BookkeepingResponseDto dto = new BookkeepingResponseDto();
        dto.setId(bookkeeping.getId());
        dto.setType(bookkeeping.getType());
        dto.setBookDate(bookkeeping.getBookDate());
        dto.setCategory(bookkeeping.getCategory());
        dto.setPrice(bookkeeping.getPrice());
        dto.setRemark(bookkeeping.getRemark());
        dto.setAddTime(bookkeeping.getAddTime());
        dto.setUpdateTime(bookkeeping.getUpdateTime());
        dto.setYear(bookkeeping.getYear());
        dto.setMonth(bookkeeping.getMonth());
        return dto;
    }
}
